import { GSprite } from "../../../../com/mui/controls/GSprite";
import { PageTool } from "../../../common/global/PageTool";
import { CursorManager } from "../../manager/CursorManager";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { EntityUtil } from "../../scene/layer/utils/EntityUtil";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { Cache } from "../../cache/Cache";
import { EGuildPos } from "../../../../Message/Game/EGuildPos";
import { MsgManager } from "../../manager/MsgManager";
import { PetIslandFightObserveVo } from "./vo/PetIslandFightObserveVo";
import { PetIslandUtil } from "./PetIslandUtil";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { SPlaceInfo } from "../../../../Message/Game/SPlaceInfo";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { RemainTimeUtil } from "../shopMall/RemainTimeUtil";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { GTextItem } from "../range/GTextItem";
import { SecTimerView } from "../common/SecTimerView";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { PetIslandMapItemTipItemRenderer } from "./renderer/PetIslandMapItemTipItemRenderer";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class PetIslandMapItemTip
    
    export  class PetIslandMapItemTip extends GSprite
    {
        constructor()
        {
            super();
            this._pageTool = new PageTool([], 3);
            this.init();
            return;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            CursorManager.hideCursor();
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */onTxtLinkHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (arg1.target.name != "attackTxtBtn") 
            {
                if (this._curType != 2) 
                {
                    this._curType = 2;
                    this._memberSp.addChild(this._defendInfoTxt);
                    DisplayUtil.removeMe(this._attackInfoTxt);
                    this._guildName.text = "[" + EntityUtil.getProxyName(this._data.guildId) + "]" + this._data.guildName;
                    this.memberSpShow = true;
                    this._defendTxtBtn.addSelectedSkin();
                    this._attackTxtBtn.removeSelectedSkin();
                }
                else 
                {
                    this._curType = 0;
                    this.memberSpShow = false;
                    this._attackTxtBtn.removeSelectedSkin();
                    this._defendTxtBtn.removeSelectedSkin();
                }
            }
            else if (this._curType != 1) 
            {
                this._curType = 1;
                this._memberSp.addChild(this._attackInfoTxt);
                DisplayUtil.removeMe(this._defendInfoTxt);
                this._guildName.text = "[" + EntityUtil.getProxyName(this._data.attackGuildId) + "]" + this._data.attackGuildName;
                this.memberSpShow = true;
                this._attackTxtBtn.addSelectedSkin();
                this._defendTxtBtn.removeSelectedSkin();
            }
            else 
            {
                this._curType = 0;
                this.memberSpShow = false;
                this._attackTxtBtn.removeSelectedSkin();
                this._defendTxtBtn.removeSelectedSkin();
            }
            this._pageSelecter.currentPage = 1;
            this.drawList();
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */onAttackHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._attackBtn.label != Language.getString(28163)) 
            {
                if (this._attackBtn.label == Language.getString(28208) || this._attackBtn.label == Language.getString(28132)) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandGarrison, this._data.placeId));
                }
                else if (this._attackBtn.label == Language.getString(28217)) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandGarrison, 0));
                }
            }
            else if (Cache.instance.petIsland.playerInfo.guildPos > EGuildPos._EGuildPosMember) 
            {
                if (this._data.protectSeconds > 0) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(28214));
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandMapAttack, this._data));
                }
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(28209));
            }
            return;
        }

        /* internal  */set memberSpShow(arg1: Boolean)
        {
            if (arg1) 
            {
                this.addChild(this._memberSp);
                this._bg.height = 320;
            }
            else 
            {
                DisplayUtil.removeMe(this._memberSp);
                this._bg.height = 160;
            }
            return;
        }

        /* internal  */onSecViewTimeChange(arg1: DataEvent): void
        {
            this._leftTime = int(arg1.data);
            if (this._leftTime <= 0 && this._tfLeftTime.parse == Language.getString(28199)) 
            {
                this._tfLeftTime.stop();
                DisplayUtil.removeMe(this._tfLeftTime);
                this._stateTxt.text = Language.getString(28200);
                this.addChild(this._stateTxt);
            }
            return;
        }

        /* internal  */onObserveHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (this._leftTime > 0) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandFightListReq, this._data.placeId));
            }
            else 
            {
                loc1 = new PetIslandFightObserveVo();
                loc1.placeId = this._data.placeId;
                loc1.isObserve = true;
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandFightObserve, loc1));
            }
            return;
        }

        /* internal  */setAttackBtnInfo(): void
        {
            if (PetIslandUtil.isInGuild(this._data.guildId)) 
            {
                this._attackBtn.enabled = true;
                this._attackBtn.label = this._data.isFighting ? Language.getString(28208) : Language.getString(28132);
                if (PetIslandUtil.isReinforce(this._data.players)) 
                {
                    this._attackBtn.label = Language.getString(28217);
                }
            }
            else if (PetIslandUtil.isInGuild(this._data.attackGuildId)) 
            {
                this._attackBtn.label = this._data.isFighting ? Language.getString(28208) : Language.getString(28163);
                this._attackBtn.enabled = !PetIslandUtil.isReinforce(this._data.attackPlayers);
            }
            else 
            {
                this._attackBtn.label = Language.getString(28163);
                this._attackBtn.enabled = true;
            }
            return;
        }

        /* internal  */setStateTxtInfo(): void
        {
            if (this._data.isFighting) 
            {
                if (this._data.fightStartSeconds > 0) 
                {
                    this._tfLeftTime.setParse(Language.getString(28199));
                    this._tfLeftTime.setLeftTime(this._data.fightStartSeconds);
                    this.addChild(this._tfLeftTime);
                    DisplayUtil.removeMe(this._stateTxt);
                }
                else 
                {
                    this._tfLeftTime.stop();
                    DisplayUtil.removeMe(this._tfLeftTime);
                    this._leftTime = 0;
                    this._stateTxt.text = Language.getString(28200);
                    this.addChild(this._stateTxt);
                }
                this.addChild(this._observeBtn);
            }
            else 
            {
                this._tfLeftTime.stop();
                DisplayUtil.removeMe(this._stateTxt);
                DisplayUtil.removeMe(this._observeBtn);
                DisplayUtil.removeMe(this._tfLeftTime);
                if (this._data.protectSeconds > 0) 
                {
                    this._stateTxt.text = "";
                    this._tfLeftTime.setParse(Language.getString(28213));
                    this._tfLeftTime.setLeftTime(this._data.protectSeconds);
                    this.addChild(this._tfLeftTime);
                }
            }
            return;
        }

        /* internal  */garrisonInfo(): void
        {
            if (this._data.guildId.id > 0) 
            {
                if (this._data.attackGuildId.id <= 0 && this._openTime == 0) 
                {
                    this._defendTxtBtn.dispatchEvent(new Object /* flash.events.MouseEvent */(flash.events.MouseEvent.CLICK));
                }
                if (this._curType == 2) 
                {
                    this._guildName.text = "[" + EntityUtil.getProxyName(this._data.guildId) + "]" + this._data.guildName;
                }
                this.addChild(this._defendTxtBtn);
            }
            else 
            {
                if (this._curType == 2) 
                {
                    this._curType = 0;
                    DisplayUtil.removeMe(this._memberSp);
                    this._defendTxtBtn.removeSelectedSkin();
                }
                DisplayUtil.removeMe(this._defendTxtBtn);
            }
            if (this._data.attackGuildId.id > 0) 
            {
                if (this._openTime == 0) 
                {
                    this._attackTxtBtn.dispatchEvent(new Object /* flash.events.MouseEvent */(flash.events.MouseEvent.CLICK));
                }
                if (this._curType == 1) 
                {
                    this._guildName.text = "[" + EntityUtil.getProxyName(this._data.attackGuildId) + "]" + this._data.attackGuildName;
                }
                this.addChild(this._attackTxtBtn);
            }
            else 
            {
                if (this._curType == 1) 
                {
                    this._curType = 0;
                    DisplayUtil.removeMe(this._memberSp);
                    this._attackTxtBtn.removeSelectedSkin();
                }
                DisplayUtil.removeMe(this._attackTxtBtn);
            }
            this.drawList();
            return;
        }

        /* internal  */drawList(): void
        {
            if (this._curType != 1) 
            {
                if (this._curType != 2) 
                {
                    return;
                }
                else 
                {
                    this._pageTool.array = this._data.players;
                }
            }
            else 
            {
                this._pageTool.array = this._data.attackPlayers;
            }
            this._pageSelecter.maxPage = this._pageTool.pagesCount;
            this._list.dataProvider = new DataProvider(this._pageTool.getByPageNo(this._pageSelecter.currentPage));
            this._list.drawNow();
            return;
        }

        /* internal  */onEquipmentPageChange(arg1: Object /* flash.events.Event */=null): void
        {
            var loc1=this._pageSelecter.currentPage;
            this._list.dataProvider = new DataProvider(this._pageTool.getByPageNo(loc1));
            this._list.drawNow();
            return;
        }

        /* internal  */onRemoveHandler(arg1: Object /* flash.events.Event */): void
        {
            this._data = null;
            this._curType = 0;
            this._openTime = 0;
            this._pageSelecter.currentPage = 1;
            this._attackTxtBtn.removeSelectedSkin();
            this._defendTxtBtn.removeSelectedSkin();
            this._tfLeftTime.stop();
            DisplayUtil.removeMe(this._tfLeftTime);
            DisplayUtil.removeMe(this._memberSp);
            this._bg.height = 160;
            return;
        }

        /* internal  */onMouseDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.startDrag();
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */onMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.stopDrag();
            arg1.stopImmediatePropagation();
            return;
        }

        public set data(arg1: SPlaceInfo)
        {
            this._data = arg1;
            var loc1=HTMLUtil.removeHtml(PetIslandUtil.getPosName(arg1.pos, false));
            this._name.htmlText = this._data.guildName != "" ? this._data.guildName + loc1 : Language.getString(28222) + loc1;
            this._quality.htmlText = GameDefConfig.instance.getPetIslandPlaceTypeName(this._data.pos.placeType);
            this._output.text = Language.getStringByParam(28160, this._data.grassRemain + "/" + this._data.grassTotal);
            this._speed.text = Language.getStringByParam(28128, this._data.exploitSpeed);
            this._stock.text = Language.getStringByParam(28161, this._data.grassCount);
            this._time.text = Language.getStringByParam(28129, RemainTimeUtil.getRemainMinute(this._data.occupySeconds, true, true, true, false, true));
            this.setAttackBtnInfo();
            this.setStateTxtInfo();
            this.garrisonInfo();
            this._bg.height = this.contains(this._memberSp) ? 320 : 160;
            var loc2;
            var loc3=((loc2 = this)._openTime + 1);
            loc2._openTime = loc3;
            return;
        }

        public get data(): SPlaceInfo
        {
            return this._data;
        }

        protected closeBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            DisplayUtil.removeMe(this);
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */init(): void
        {
            super.createDisposedChildren();
            this._bg = ObjCreate.createBg(0, 0, 230, 320, this, ImagesConst.ToolTipBg);
            ObjCreate.createBg(0, 0, 230, 160, this);
            ObjCreate.createBg(0, 30, 200, 2, this, ImagesConst.SplitLine);
            this._name = ObjCreate.createGTextField("", 8, 9, 150, 20, this, GlobalStyle._textFormat6);
            this._name.mouseEnabled = false;
            this._quality = ObjCreate.createGTextField("", 150, 8, 150, 20, this, new GTextFormat(FontUtil.xingkaiName, 18));
            this._quality.mouseEnabled = false;
            this._output = ObjCreate.createGTextField("", 8, 35, 150, 20, this, GlobalStyle._textFormat6);
            this._speed = ObjCreate.createGTextField("", 8, 55, 150, 20, this, GlobalStyle._textFormat6);
            this._stock = ObjCreate.createGTextField("", 8, 75, 150, 20, this, GlobalStyle._textFormat6);
            this._time = ObjCreate.createGTextField("", 8, 95, 150, 20, this, GlobalStyle._textFormat6);
            this._attackBtn = ObjCreate.createGButton(Language.getString(28163), 170, 35, 49, 26, this, "ButtonRed");
            ObjCreate.createGTextField(Language.getString(28212), 8, 115, 40, 20, this, GlobalStyle._textFormat6);
            this._stateTxt = ObjCreate.createGTextField("", 42, 115, 40, 20, null, GlobalStyle._textFormat5);
            this._observeBtn = ObjCreate.createGButton(Language.getString(28251), 150, 115, 40, 20, this);
            this._observeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onObserveHandler);
            ObjCreate.createGTextField(Language.getString(28231), 8, 135, 80, 20, this, GlobalStyle._textFormat6);
            this._attackTxtBtn = new GTextItem({"text": Language.getString(28232), "color": 0}, 40, 20);
            this._attackTxtBtn.name = "attackTxtBtn";
            ObjCreate.setObjAttri(this._attackTxtBtn, 80, 135, -1, -1);
            this._defendTxtBtn = new GTextItem({"text": Language.getString(28233), "color": 0}, 40, 20);
            ObjCreate.setObjAttri(this._defendTxtBtn, 140, 135, -1, -1);
            this._defendTxtBtn.name = "defendTxtBtn";
            this._tfLeftTime = new SecTimerView();
            this._tfLeftTime.mouseEnabled = false;
            this._tfLeftTime.setParse(Language.getString(28199));
            this._tfLeftTime.defaultTextFormat = GlobalStyle.setTextFormatAlign(GlobalStyle._textFormat5, flash.text.TextFormatAlign.CENTER);
            this._tfLeftTime.filters = [FilterConst.glowFilter];
            this._tfLeftTime.addEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChange);
            ObjCreate.setObjAttri(this._tfLeftTime, 42, 115, 110, 20);
            this._memberSp = new GSprite();
            ObjCreate.setObjAttri(this._memberSp, 0, 160, -1, -1);
            this._attackInfoTxt = ObjCreate.createGTextField(Language.getString(28234), 8, 5, 220, 20, null, GlobalStyle._textFormatRed);
            this._defendInfoTxt = ObjCreate.createGTextField(Language.getString(28235), 8, 5, 220, 20);
            this._guildName = ObjCreate.createGTextField("", 75, 5, 152, 20, this._memberSp, GlobalStyle.setTextFormatAlign(GlobalStyle._textFormat1, flash.text.TextFormatAlign.CENTER));
            ObjCreate.createBg(0, 28, 230, 2, this._memberSp, ImagesConst.SplitLine);
            this._list = ObjCreate.createTileList(0, 30, 230, 100, this._memberSp);
            this._list.scrollPolicy = ScrollPolicy.OFF;
            this._list.columnWidth = 230;
            this._list.rowHeight = 33;
            this._list.setStyle("cellRenderer", PetIslandMapItemTipItemRenderer);
            this._pageSelecter = ObjCreate.createPageSelecter(54, 135, this._memberSp);
            this._pageSelecter.mode = PageSelecter.CompleteMode;
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.onEquipmentPageChange);
            this._attackBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onAttackHandler);
            this._viewCloseBtn = ObjCreate.createGButton("", 212, 0, 19, 19, this, "CloseButton");
            this._viewCloseBtn.addEventListener(flash.events.MouseEvent.CLICK, this.closeBtnClickHandler);
            this._attackTxtBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onTxtLinkHandler);
            this._defendTxtBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onTxtLinkHandler);
            this.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMouseDownHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMouseUpHandler);
            return;
        }

        /* internal */ /* var */_memberSp: GSprite;

        /* internal */ /* var */_list: GTileList;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_output: GTextFiled;

        /* internal */ /* var */_data: SPlaceInfo;

        /* internal */ /* var */_curType: int;

        /* internal */ /* var */_openTime: int;

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_pageTool: PageTool;

        /* internal */ /* var */_viewCloseBtn: GButton;

        /* internal */ /* var */_name: GTextFiled;

        /* internal */ /* var */_quality: GTextFiled;

        /* internal */ /* var */_speed: GTextFiled;

        /* internal */ /* var */_stock: GTextFiled;

        /* internal */ /* var */_time: GTextFiled;

        /* internal */ /* var */_attackBtn: GButton;

        /* internal */ /* var */_stateTxt: GTextFiled;

        /* internal */ /* var */_tfLeftTime: SecTimerView;

        /* internal */ /* var */_observeBtn: GButton;

        /* internal */ /* var */_guildName: GTextFiled;

        /* internal */ /* var */_attackTxtBtn: GTextItem;

        /* internal */ /* var */_defendTxtBtn: GTextItem;

        /* internal */ /* var */_attackInfoTxt: GTextFiled;

        /* internal */ /* var */_defendInfoTxt: GTextFiled;

        /* internal */ /* var */_leftTime: int;
    }
